package com.cl.short_video_java.web.client.concern;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.annotation.NoRepeatSubmit;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.pojo.VideoLikeCollect;
import com.cl.short_video_java.service.VideoLikeCollectService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 付
 * @Date 2024-11-24 13:27
 * @Version 1.0
 * @description
 * @since 1.0
 */
@RestController
@RequestMapping("/client")
public class CollectController {

	private VideoLikeCollectService collectService;

	public CollectController(VideoLikeCollectService collectService) {
		this.collectService = collectService;
	}

	/**
	 * 查询收藏-点赞列表
	 *
	 * @param type
	 * @return
	 */
	@GetMapping("/like_collect")
	@Login(issuer = Const.GRADE_USER)
	public Result getLikeCollect(@RequestParam("type") Integer type, @RequestParam("current") Integer current, HttpServletRequest request) {
		Page<VideoLikeCollect> page = collectService.likeOrCollect(type, request, current);
		return Result.success(page);
	}

	/**
	 * 取消点赞-收藏
	 *
	 * @param type    3-收藏，4-点赞
	 * @param videoId 视频id
	 * @param request
	 * @return
	 */
	@GetMapping("/cancel")
	@NoRepeatSubmit(lockTime = 1)
	@Login(issuer = Const.GRADE_USER)
	public Result cancelCollect(@RequestParam("type") Integer type, @RequestParam("videoId") Integer videoId, HttpServletRequest request) {
		collectService.cancel(type, videoId, request);
		return Result.success();
	}

}
